package LeetCode.month02.day40;

import java.util.HashSet;
import java.util.Set;

public class No03 {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("pwwkew"));
    }
    public static int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int left = 0;
        int res = 0;
        int n = s.length();
        for (int i = 0; i < n; i++) {
            while(!set.isEmpty()&&set.contains(s.charAt(i))){
                set.remove(s.charAt(left++));
            }
            set.add(s.charAt(i));
            res = Math.max(i-left+1,res);
        }
        return res;
    }
}
